package com.gary.spring.awreInit;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author peng_rui
 * @date 2022/6/26
 */
public class MyBean implements BeanNameAware, ApplicationContextAware {

    /**
     * BeanNameAware 接口中需要实现的方法，作用是创建bean时，写入bean的名字
     * @param name
     */
    @Override
    public void setBeanName(String name) {
        System.out.println("写入bean的名字 " + name);
    }

    /**
     * 设置bean的context容器
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("myBean的容器" + applicationContext);
    }
}
